#!/usr/bin/perl -W
use strict;
use DBI;

my $dbh = DBI->connect("DBI:mysql:getRSS", "yura", "password");
my $sth0 = $dbh->prepare("BEGIN");
my $sth1 = $dbh->prepare("SELECT `itemId`, `itemContent` FROM `items`");
my $sth2 = $dbh->prepare("DELETE FROM `items`");
my $sth3 = $dbh->prepare("COMMIT");

print "Content-type: text/xml\n\n";
print "<?xml version='1.0'?>\n";
print "<!--You can poll this feed as often as you like, but please don't spider the links.\n";
print "Mail dev\@livejournal.com if you have any questions/interesting research ideas.-->\n";
print "<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:lj='http://livejournal.org/rss/lj/1.0/' xmlns='http://purl.org/rss/1.0/'>\n";
print "<channel rdf:about='http://localhost/cgi-bin/getRSS.cgi'><title>Latest LiveJournal.com Posts</title><link>http://www.livejournal.com/stats/latest.bml</link><description>Latest public posts at LiveJournal.com.</description>\n";
print "<items><rdf:Seq>\n";

my ($id, $content);

$sth0->execute;
$sth1->execute;
while (($id, $content) = $sth1->fetchrow()) {
  print "<rdf:li resource='" . $id . "' />\n";
}
print "</rdf:Seq></items></channel>\n";
$sth1->execute;
while (($id, $content) = $sth1->fetchrow()) {
  print $content;
}
print "</rdf:RDF>\n";
$sth2->execute;
$sth3->execute;
